package cn.sdhuijin.tree.branchtree;

/**
 * 节点类
 */
public class Node {

	private String branchId;
	private String branchName;
	private String branchAddress;
	private String branchHead;
	private String branchRemarks;
	private String branchPhone;
	private String branchOperate;
	private String uiProvider;
	private String cls;
	private String iconCls;
	private String parentId;
	private Children children = new Children();

	// 先序遍历，拼接JSON字符串
	public String toString() {
		String result = "{" + "branchId : '" + branchId + "'"
				+ ", branchName : '" + branchName + "'" + ", branchAddress : "
				+ isNullAppend(branchAddress) + ", branchHead : "
				+ isNullAppend(branchHead) + ", branchRemarks : "
				+ isNullAppend(branchRemarks) + ", branchPhone :"
				+ isNullAppend(branchPhone) + ", uiProvider : '" + "col" + "'";
		if (children != null && children.getSize() != 0) {
			result += ", expanded:true"
					+ ", cls : '"
					+ "master-task"
					+ "'"
					+ ", iconCls : '"
					+ "task-folder"
					+ "'"
					+ ", branchOperate : '"
					+ "<div class=\"branches_view\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class=\"branches_edit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>'"
					+ ", children : " + children.toString();
		} else {
//			result += ", branchOperate : '"
//					+ "<div class=\"branches_view\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class=\"branches_edit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class=\"branches_delete\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>'"
//					+ ", iconCls : '" + "task" + "'" + ", leaf : true";
			result += ", branchOperate : '"
					+ "<div class=\"branches_view\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class=\"branches_edit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>'"
					+ ", iconCls : '" + "task" + "'" + ", leaf : true";
		}

		return result + "}";
	}

	public String isNullAppend(String str) {
		if (str == null) {
			return "" + null + "";
		} else {
			return "'" + str + "'";
		}
	}

	// 兄弟节点横向排序
	public void sortChildren() {
		if (children != null && children.getSize() != 0) {
			children.sortChildren();
		}
	}

	// 添加孩子节点
	public void addChild(Node node) {
		this.children.addChild(node);
	}

	/**
	 * @return the branchId
	 */
	public String getBranchId() {
		return branchId;
	}

	/**
	 * @param branchId
	 *            the branchId to set
	 */
	public void setBranchId(String branchId) {
		this.branchId = branchId;
	}

	/**
	 * @return the branchName
	 */
	public String getBranchName() {
		return branchName;
	}

	/**
	 * @param branchName
	 *            the branchName to set
	 */
	public void setBranchName(String branchName) {
		this.branchName = branchName;
	}

	/**
	 * @return the branchAddress
	 */
	public String getBranchAddress() {
		return branchAddress;
	}

	/**
	 * @param branchAddress
	 *            the branchAddress to set
	 */
	public void setBranchAddress(String branchAddress) {
		this.branchAddress = branchAddress;
	}

	/**
	 * @return the branchHead
	 */
	public String getBranchHead() {
		return branchHead;
	}

	/**
	 * @param branchHead
	 *            the branchHead to set
	 */
	public void setBranchHead(String branchHead) {
		this.branchHead = branchHead;
	}

	/**
	 * @return the branchRemarks
	 */
	public String getBranchRemarks() {
		return branchRemarks;
	}

	/**
	 * @param branchRemarks
	 *            the branchRemarks to set
	 */
	public void setBranchRemarks(String branchRemarks) {
		this.branchRemarks = branchRemarks;
	}

	/**
	 * @return the branchPhone
	 */
	public String getBranchPhone() {
		return branchPhone;
	}

	/**
	 * @param branchPhone
	 *            the branchPhone to set
	 */
	public void setBranchPhone(String branchPhone) {
		this.branchPhone = branchPhone;
	}

	/**
	 * @return the branchOperate
	 */
	public String getBranchOperate() {
		return branchOperate;
	}

	/**
	 * @param branchOperate
	 *            the branchOperate to set
	 */
	public void setBranchOperate(String branchOperate) {
		this.branchOperate = branchOperate;
	}

	/**
	 * @return the uiProvider
	 */
	public String getUiProvider() {
		return uiProvider;
	}

	/**
	 * @param uiProvider
	 *            the uiProvider to set
	 */
	public void setUiProvider(String uiProvider) {
		this.uiProvider = uiProvider;
	}

	/**
	 * @return the cls
	 */
	public String getCls() {
		return cls;
	}

	/**
	 * @param cls
	 *            the cls to set
	 */
	public void setCls(String cls) {
		this.cls = cls;
	}

	/**
	 * @return the iconCls
	 */
	public String getIconCls() {
		return iconCls;
	}

	/**
	 * @param iconCls
	 *            the iconCls to set
	 */
	public void setIconCls(String iconCls) {
		this.iconCls = iconCls;
	}

	/**
	 * @return the children
	 */
	public Children getChildren() {
		return children;
	}

	/**
	 * @param children
	 *            the children to set
	 */
	public void setChildren(Children children) {
		this.children = children;
	}

	/**
	 * @return the parentId
	 */
	public String getParentId() {
		return parentId;
	}

	/**
	 * @param parentId
	 *            the parentId to set
	 */
	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

}
